//package vip.xiaonuo.dev.modular.job.util;
//
//import com.alibaba.fastjson2.JSON;
//import com.alibaba.fastjson2.JSONArray;
//import com.alibaba.fastjson2.JSONObject;
//import com.ruoyi.system.domain.HisCallRec;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.http.HttpEntity;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpMethod;
//import org.springframework.http.ResponseEntity;
//import org.springframework.stereotype.Component;
//import org.springframework.web.client.RestTemplate;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.stream.Collectors;
//
///**
// * 历史话单接口工具类
// */
//@Component
//public class TousuApiUtil {
//
//    private static final Logger log = LoggerFactory.getLogger(TousuApiUtil.class);
//
//    private static final String preUrl = "http://183.247.194.62:53333";
//    // http://183.247.194.62:5005/data/e_cdr_20240826/1724651004000/1724651000000
//
//    public List<HisCallRec> getHisCallRec(String tableName, String maxCallid){
//        List<HisCallRec> list = new ArrayList<>();
//        String url = preUrl + "/get_data/" + tableName + "/" + maxCallid;
//        RestTemplate restTemplate = new RestTemplate();
//        HttpHeaders httpHeaders = new HttpHeaders();
//        HttpEntity<String> httpEntity = new HttpEntity<String>(httpHeaders);
//        ResponseEntity<String> responseEntity = restTemplate.exchange(url,HttpMethod.GET, httpEntity, String.class);
//        if (responseEntity.getStatusCode().is2xxSuccessful() && responseEntity.hasBody()) {
//            String responseBody = responseEntity.getBody();
//            JSONArray jsonArray = JSONArray.parseArray(responseBody);
//            list = jsonArray.stream().map(item ->{
//                JSONObject object = JSON.parseObject(item.toString());
//                HisCallRec rec = convertObj2Rec(object);
//                return rec;
//            }).collect(Collectors.toList());
//        }
//        return list;
//    }
//
//    public List<HisCallRec> getVosBetweenData(String tableName, int from, int to){
//        List<HisCallRec> list = new ArrayList<>();
//        String url = preUrl + "/get_between/" + tableName + "/" + from + "/" + to;
//        RestTemplate restTemplate = new RestTemplate();
//        HttpHeaders httpHeaders = new HttpHeaders();
//        HttpEntity<String> httpEntity = new HttpEntity<String>(httpHeaders);
//        ResponseEntity<String> responseEntity = restTemplate.exchange(url,HttpMethod.GET, httpEntity, String.class);
//        if (responseEntity.getStatusCode().is2xxSuccessful() && responseEntity.hasBody()) {
//            String responseBody = responseEntity.getBody();
//            JSONArray jsonArray = JSONArray.parseArray(responseBody);
//            list = jsonArray.stream().map(item ->{
//                JSONObject object = JSON.parseObject(item.toString());
//                HisCallRec rec = convertObj2Rec(object);
//                return rec;
//            }).collect(Collectors.toList());
//        }
//        return list;
//    }
//
//    public JSONObject getMinAndMaxData(String tableName){
//        JSONObject jsonObject = new JSONObject();
//        String url = preUrl + "/get_min_max/" + tableName;
//        RestTemplate restTemplate = new RestTemplate();
//        HttpHeaders httpHeaders = new HttpHeaders();
//        HttpEntity<String> httpEntity = new HttpEntity<String>(httpHeaders);
//        ResponseEntity<String> responseEntity = restTemplate.exchange(url,HttpMethod.GET, httpEntity, String.class);
//        if (responseEntity.getStatusCode().is2xxSuccessful() && responseEntity.hasBody()) {
//            String responseBody = responseEntity.getBody();
//            JSONArray jsonArray = JSONArray.parseArray(responseBody);
//            if (jsonArray != null) {
//                jsonObject = jsonArray.getJSONObject(0);
//            }
//            return jsonObject;
//        }
//        return jsonObject;
//    }
//
//    public HisCallRec convertObj2Rec(JSONObject object){
//        HisCallRec rec = new HisCallRec();
//        rec.setCallid(object.getString("id"));
//        rec.setCallere164(object.getString("callere164"));
//        rec.setCalleraccesse164(object.getString("calleraccesse164"));
//        rec.setCalleee164(object.getString("calleee164"));
//        rec.setCalleeaccesse164(object.getString("calleeaccesse164"));
//        rec.setCallerip(object.getString("callerip"));
//        rec.setCallerrtpip(object.getString("callerrtpip"));
//        rec.setCallercodec(object.getString("callercodec"));
//        rec.setCallergatewayid(object.getString("callergatewayid"));
//        rec.setCallerproductid(object.getString("callerproductid"));
//        rec.setCallertogatewaye164(object.getString("callertogatewaye164"));
//        rec.setCallertype(object.getString("callertype"));
//        rec.setCalleeip(object.getString("calleeip"));
//        rec.setCalleertpip(object.getString("calleertpip"));
//        rec.setCalleecodec(object.getString("calleecodec"));
//        rec.setCalleegatewayid(object.getString("calleegatewayid"));
//        rec.setCalleeproductid(object.getString("calleeproductid"));
//        rec.setCalleetogatewaye164(object.getString("calleetogatewaye164"));
//        rec.setCalleetype(object.getString("calleetype"));
//        rec.setBillingmode(object.getString("billingmode"));
//        rec.setCalllevel(object.getString("calllevel"));
//        rec.setAgentfeetime(object.getString("agentfeetime"));
//        rec.setStarttime(object.getString("starttime"));
//        rec.setStoptime(object.getString("stoptime"));
//        rec.setCallerpdd(object.getString("callerpdd"));
//        rec.setCalleepdd(object.getString("calleepdd"));
//        rec.setHoldtime(object.getString("holdtime"));
//        rec.setCallerareacode(object.getString("callerareacode"));
//        rec.setFeetime(object.getString("feetime"));
//        rec.setFee(object.getString("fee"));
//        rec.setTax(object.getString("tax"));
//        rec.setSuitefee(object.getString("suitefee"));
//        rec.setSuitefeetime(object.getString("suitefeetime"));
//        rec.setIncomefee(object.getString("incomefee"));
//        rec.setIncometax(object.getString("incometax"));
//        rec.setCustomeraccount(object.getString("customeraccount"));
//        rec.setCustomername(object.getString("customername"));
//        rec.setCalleeareacode(object.getString("calleeareacode"));
//        rec.setAgentfee(object.getString("agentfee"));
//        rec.setAgenttax(object.getString("agenttax"));
//        rec.setAgentsuitefee(object.getString("agentsuitefee"));
//        rec.setAgentsuitefeetime(object.getString("agentsuitefeetime"));
//        rec.setAgentaccount(object.getString("agentaccount"));
//        rec.setAgentname(object.getString("agentname"));
//        rec.setFlowno(object.getString("flowno"));
//        rec.setFeetime(object.getString("feetime"));
//        rec.setSoftswitchname(object.getString("softswitchname"));
//        rec.setSoftswitchcallid(object.getString("softswitchcallid"));
//        rec.setCalleroriginalcallid(object.getString("calleroriginalcallid"));
//        rec.setCalleecallid(object.getString("calleecallid"));
//        rec.setCalleroriginalinfo(object.getString("calleroriginalinfo"));
//        rec.setRtpforward(object.getString("rtpforward"));
//        rec.setEnddirection(object.getString("enddirection"));
//        rec.setEndreason(object.getString("endreason"));
//        rec.setBillingtype(object.getString("billingtype"));
//        rec.setCdrlevel(object.getString("cdrlevel"));
//        rec.setAgentcdrId(object.getString("agentcdrId"));
//        rec.setSipreasonheader(object.getString("sipreasonheader"));
//        rec.setRecordstarttime(object.getString("recordstarttime"));
//        rec.setTransactionid(object.getString("transactionid"));
//        return rec;
//    }
//}
